package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;

import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Adapter.MoreSummonerAdapter;
import liumengbaio.lolzhangyoubao.Activity.InFo.SummonerSkillsInfo;
import liumengbaio.lolzhangyoubao.Activity.utils.SummonerSkillsUtils;
import liumengbaio.lolzhangyoubao.R;

public class SummonerSkillActivity extends AppCompatActivity {
    private List<SummonerSkillsInfo> mList;
    private MoreSummonerAdapter mMoreSummonerAdapter;
    private GridView mGridView;
    private ImageView back;
    private int flag = 0;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_summoner_skill);
        sp = getSharedPreferences("summonerSkill", MODE_PRIVATE);
        editor = sp.edit();
        initView();
        initData();
        initEvent();
    }

    private void initEvent() {
        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                flag += 1;
                editor.putString("pic_url"+flag, mList.get(position).getPic_url());
                if (flag == 2) {
                    editor.putString("flag",""+flag);
                    editor.commit();
                    finish();
                }
            }
        });
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initData() {
        mList = SummonerSkillsUtils.getSummonerSkillsInfo(this);
        mMoreSummonerAdapter = new MoreSummonerAdapter(mList, this);
        mGridView.setAdapter(mMoreSummonerAdapter);
    }

    private void initView() {
        mGridView = (GridView) findViewById(R.id.more_gridView);
        back = (ImageView) findViewById(R.id.more_skill_back);
    }
}
